
#-*-coding: UTF-8 -*-

'''
程序方法调用
/*PHP是世界上最好的语言*/

'''
import hmac, hashlib,websocket
from websocket import create_connection
from base_config import *
import time
class Helper( object ):

    def __init__(self):

        pass

    # 生成签名
    @staticmethod
    def genSign( params ):

        # 密钥
        secret_key = SECRET_KEY.encode('ascii')

        # 判断是否属于json格式
        if isinstance( params ,dict ) :

            md = hashlib.md5()

            secret_value = ''

            # 遍历key&value 获取拼接内容

            for k , v in zip( params.keys(),params.values() ):

                secret_value =  secret_value + k +  '=' +  hashlib.md5( v.encode()).hexdigest()
            secret_value = secret_value.encode('ascii')

            sign = hmac.new(secret_key,secret_value, hashlib.md5).hexdigest()

            return sign


        elif isinstance( params , str ):

            md = hashlib.md5()

            # source加密

            md.update('9999'.encode('utf-8'))

            md5_source = md.hexdigest()

            # 关键词加密

            md5_name = hashlib.md5(params.encode()).hexdigest()

            secret_value = ('keywords=' + md5_name + 'source=' + md5_source ).encode('ascii')

            sign = hmac.new(secret_key, secret_value, hashlib.md5).hexdigest()

            return sign


    # 生成当前时间
    @staticmethod
    def getCurrentDate(formatdate="%Y-%m-%d"):

        currentTime = time.strftime(formatdate, time.localtime(time.time()))

        return currentTime


#====================================V2.0=====================================================
    @staticmethod
    def webConn(data):

        ws = create_connection("ws://pddtoolbox.penglingcheng.com:7020")

        if ws.connected:

            ws.send(data, opcode=websocket.ABNF.OPCODE_TEXT)




if __name__ == '__main__':


    # data = {
    #
    #     'taskid':'3401'
    # }
    #
    #
    # print( Helper.genSign(data) )


    data = str([{'goodsid': '7237182852', 'goodsname': '空胶囊壳药粉填充板空心胶囊壳自动工具家用0号100孔中药粉灌装器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-04-06/569510ea4bc919ca5ba8abf963548fb8.jpeg', 'price': '58.80', 'rank': '21', 'salescount': '0'}, {'goodsid': '6995436771', 'goodsname': '胶囊板0号100孔胶囊壳灌装器胶囊填充板装药器家用', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-03-29/b5d1b055d1de93106d2ec252e281ae4d.jpeg', 'price': '24.70', 'rank': '22', 'salescount': '0'}, {'goodsid': '32949764388', 'goodsname': '胶囊板0号1号2号3号4号100孔200孔400孔胶囊壳装药器灌装板填充粉', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-08-09/cb4533908ba5aa042e3add35b7a1bd6f.jpeg', 'price': '69.60', 'rank': '23', 'salescount': '0'}, {'goodsid': '6107382863', 'goodsname': '胶囊板0号1号2号3号4号200孔胶囊壳装药器填充板灌装机罐装器灌装', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-03-02/d494d714234b5332c2e52b3618013d53.jpeg', 'price': '67.90', 'rank': '24', 'salescount': '0'}, {'goodsid': '56605914', 'goodsname': '植物胶囊壳1000粒套装包含填充板 口服胶囊', 'keywords': '牛肉干', 'pic': 'http://omsproductionimg.yangkeduo.com/images/2017-08-16/c4a9ce76efc932d2dbae2e91c68ce8f4.jpeg', 'price': '186.00', 'rank': '25', 'salescount': '172'}, {'goodsid': '23728678697', 'goodsname': '手工胶囊填充板灌装器0号100孔家用口服可食用植物空胶囊壳装粉器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-07-13/0fb6d0c933fe7e136a5b0725537c0e8e.jpeg', 'price': '50.40', 'rank': '26', 'salescount': '0'}, {'goodsid': '18511252630', 'goodsname': '胶囊壳0号00号1号灌粉100孔专用板 植物胶囊壳外壳皮胶囊板灌装器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-06-22/a376dc28dcad291d59cd7aab1fbfddfc.jpeg', 'price': '58.00', 'rank': '27', 'salescount': '0'}, {'goodsid': '5799832760', 'goodsname': '胶囊板0号100孔胶囊壳灌装器胶囊填充板装药器家用', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-03-31/d08b6027e2935e6155e860034368ae49.jpeg', 'price': '37.00', 'rank': '28', 'salescount': '24'}, {'goodsid': '29239384101', 'goodsname': '胶囊板0号100孔胶囊壳灌装器胶囊填充板装药器家用', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-08-01/c542a2f62abbdb412fa1b989c0bd67c0.jpeg', 'price': '47.30', 'rank': '29', 'salescount': '0'}, {'goodsid': '6869866826', 'goodsname': '0号00#000#半流体润滑脂减速机润滑油泵车极压抗磨黄油锂基脂15KG', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-03-25/cd3b45d4a1a5fcb981f3bbbc38d70b8a.jpeg', 'price': '165.00', 'rank': '30', 'salescount': '32'}, {'goodsid': '13658671779', 'goodsname': '0号1号植物空胶囊壳口服灌装任意粉空心胶壳胶囊皮食用1000粒包邮', 'keywords': '牛肉干', 'pic': 'https://t00img.yangkeduo.com/goods/images/2018-12-09/749324407df24e18914642051e5642ce.jpeg', 'price': '18.00', 'rank': '31', 'salescount': '73'}, {'goodsid': '3783548974', 'goodsname': '申布质砂布120目棕刚玉砂布0号铁砂纸铁砂皮砂纸', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2018-10-30/8bf87aedad8b00d6f667461463a923b5.jpeg', 'price': '82.50', 'rank': '32', 'salescount': '2'}, {'goodsid': '33222570327', 'goodsname': '0号100孔胶囊板填充灌装器胶囊壳灌药灌粉装药家用手工半自动神器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-08-10/d289ce8e069fb6445f01b41949887a2b.jpeg', 'price': '44.82', 'rank': '33', 'salescount': '0'}, {'goodsid': '5799191813', 'goodsname': '0号100孔胶囊填充板胶囊板灌装器胶囊壳灌粉器灌药装药家用神器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-04-02/0bcbfb47918d40bc9861fc1c682e9b82.jpeg', 'price': '37.00', 'rank': '34', 'salescount': '6'}, {'goodsid': '21491798202', 'goodsname': '0号100孔胶囊填充板灌装器胶囊壳灌粉灌药装药家用半自动手工神器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-07-04/25352d4ec59b4202bf48dfdea6b7fefd.jpeg', 'price': '44.80', 'rank': '35', 'salescount': '0'}, {'goodsid': '13169466871', 'goodsname': '0号100孔胶囊板填充灌装器胶囊壳灌药灌粉装药家用手工半自动神器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-06-07/19d579f43332ee1cd8450a40b93d130a.jpeg', 'price': '39.90', 'rank': '36', 'salescount': '0'}, {'goodsid': '56528730', 'goodsname': '填充板 胶囊板 胶囊器 胶囊灌装器 胶囊填充', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2018-08-21/a3fefc97e950d9efea432ccf7f6525b7.jpeg', 'price': '26.00', 'rank': '37', 'salescount': '544'}, {'goodsid': '7102282542', 'goodsname': '2019新款胶囊填充板0号100孔灌装器胶囊壳灌粉器灌药装药家用神器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-04-01/9bcde50ede0e77cceb973dc73dacd24d.jpeg', 'price': '21.40', 'rank': '38', 'salescount': '2'}, {'goodsid': '34088366978', 'goodsname': '胶囊板0号空胶囊胶囊壳灌装器胶囊填充板胶囊灌装机胶囊装粉器', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-08-13/5c23f0730a591a9d8917460dd2ab2187.jpeg', 'price': '23.88', 'rank': '39', 'salescount': '0'}, {'goodsid': '5819096572', 'goodsname': '透明第三代0号18款不漏粉100孔胶囊填充板胶囊灌神器灌粉家用装药', 'keywords': '牛肉干', 'pic': 'http://t00img.yangkeduo.com/goods/images/2019-03-18/860b3d6ecbc131157b4d0717a49a2348.jpeg', 'price': '49.00', 'rank': '40', 'salescount': '18'}])


    Helper.main( data )




